package com.colis.quartz.common.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.List;

/**
 * <p> 描述： </p>
 *
 * @author wlp
 * @version 1.0.0
 * @date 2021/12/6 16:38
 */
@Data
@AllArgsConstructor
@ApiModel("分页结果返回数据")
public class PageResult<R> implements Serializable {

    @ApiModelProperty(value = "分页数据")
    private List<R> dataList;

    @ApiModelProperty(value = "总记录数")
    private Long count;

    @ApiModelProperty(value = "总页数")
    private Integer pageCount;

    @ApiModelProperty(value = "当前记录数")
    private Integer pageSize;

    @ApiModelProperty(value = "当前页数")
    private Integer pageIndex;

    public static <T> PageResult<T> start(Page<T> page) {
        return new PageResult<T>(page.getContent(), page.getTotalElements(), page.getTotalPages(), page.getSize(), page.getNumber() + 1);
    }
}
